package com.winit.openapi.ece.utils;

import com.alibaba.fastjson.JSONObject;
import com.winit.openapi.util.ValidateUtil;

/**
 * 工具类 校验json参数格式
 * 
 * @version <pre>
 * Author   Version     Date        Changes
 * changjun.xiang   1.0         2016年4月11日  Created
 *
 * </pre>
 * @since 1.
 */
public class EceLogisticInfofieldValidator {

    /**
     * 校验抵达口岸时间json参数
     * 
     * @param json
     */
    public static void validateEceArriveDomesticPort(JSONObject json) {
        validateBaseEceLogisticsPara(json);
    }

    public static void validateEceInBound(JSONObject json) {
        validateBaseEceLogisticsPara(json);
        ValidateUtil.validNotNull(json, "weight");
        ValidateUtil.validBigDecimal(json, "weight", true);
        ValidateUtil.validBigDecimal(json, "height", false);
        ValidateUtil.validBigDecimal(json, "width", false);
        ValidateUtil.validBigDecimal(json, "length", false);

    }
    
    /**
     *  校验修改订单跟踪号参数
     * 
     * @param json
     */
    public static void validUpdateTrackingNoField(JSONObject json) {
        ValidateUtil.validNotNull(json, "orderNo");
        ValidateUtil.validNotNull(json, "trackingNo");
        
        ValidateUtil.validMaxLength(json, "orderNo", 32);
        ValidateUtil.validMaxLength(json, "trackingNo", 64);
    }

    public static void validateEceOutBound(JSONObject json) {
        validateBaseEceLogisticsPara(json);

    }

    public static void validateEceCustomsClearance(JSONObject json) {
        validateBaseEceLogisticsPara(json);

    }

    public static void validateEceTransportToExpress(JSONObject json) {
        validateBaseEceLogisticsPara(json);
        ValidateUtil.valid(json, "trackingNo", 32, true);
        ValidateUtil.valid(json, "expresscompany", 64, true);

    }

    public static void validateEceFlight(JSONObject json) {
        ValidateUtil.valid(json, "orderNo", 32, true);
        ValidateUtil.valid(json, "airlines", 64, true);
        ValidateUtil.valid(json, "flight", 64, true);
        ValidateUtil.valid(json, "masterWaybillNo", 64, true);
        ValidateUtil.validNotNull(json, "onTransferTime");
        ValidateUtil.validDateString(json, "onTransferTime", "yyyy-MM-dd HH:mm:ss");

    }

    private static void validateBaseEceLogisticsPara(JSONObject json) {
        ValidateUtil.valid(json, "orderNo", 32, true);
        ValidateUtil.validNotNull(json, "occurTime");
        ValidateUtil.validDateString(json, "occurTime", "yyyy-MM-dd HH:mm:ss");
    }
}
